package com.glsx.auto;

import com.google.common.base.CaseFormat;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by linxy on 2017/4/18.
 */
public class Utils {


    public static boolean createDirectories(String path) {
        File dir = new File(path);
        return dir.exists() || dir.mkdirs();
    }

    public static File javaFile(String dir, String name) {
        return new File(dir + File.pathSeparatorChar + name + ".java");
    }

    public static InputStream getResourceAsStream(String resourcePath) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
    }

    public static String readResource(String resourcePath) throws IOException {
        return CharStreams.toString(new InputStreamReader(getResourceAsStream(resourcePath), Charsets.UTF_8));
    }

    public static String typeToName(String type) {
        return  CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, type);
    }

}
